package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.geom.Point;
import flash.geom.Rectangle;

[SWF(width=480, height=320, frameRate=24, backgroundColor=0xE2E2E2)]
public class ActionScriptBlittingPart2 extends Sprite
{
	
	public function ActionScriptBlittingPart2()
	{
		// Create input bitmap instance
		spritesheet = (new BrownCollector() as Bitmap).bitmapData;

		// Add a Bitmap to the display list that will copyPixels() to.
		canvas = new BitmapData(480, 320, true, 0xFFFFFF);
		addChild(new Bitmap(canvas));
		
		rect = new Rectangle(0, 0, 40, 40); // 1st Tile
		/** Section 1 ** //
		// rect = new Rectangle(40, 0, 40, 40); // 2nd Tile
		// rect = new Rectangle(80, 0, 40, 40); // 3rd Tile
		// ...
		// rect = new Rectangle(160, 120, 40, 40); // 20th Tile
		canvas.copyPixels(spritesheet, rect, new Point(0, 0));
		//** END Section 1 **/
		
		//** Section 2 ** // 
		for (var i:int = 0; i < 20; i++)
		{
			rect.x = (i % 5) * 40;
			rect.y = int(i / 5) * 40;
			//canvas.copyPixels(spritesheet, rect, new Point(i*10, 0));
			// Section 3: 
			 canvas.copyPixels(spritesheet, rect, 
							new Point(i*10, 0), null, null, true);
		}
		//** END Section 2 **/
	}
	
	[Embed(source="spritesheets/browncollector.png")]
	public var BrownCollector:Class;
	
	public var canvas:BitmapData;
	public var spritesheet:BitmapData;
	public var rect:Rectangle;
}
}